package com.project.export

import org.apache.spark.SparkConf
import org.apache.spark.sql.{SaveMode, SparkSession}

object university_information {
  def main(args: Array[String]): Unit = {
    //-:Spark配置对象
    val sparkConf = new SparkConf()
      .setMaster("local[*]")
    //-:sparkSession对象
    val sparkSession = SparkSession
      .builder()
      .config(sparkConf)
      //-:开启hive的支持
      .enableHiveSupport()
      .appName("University_Information")
      .getOrCreate()
    //-:读取hive中对应表的内容
    val df_colleges = sparkSession.sql("select school,province,school_level,school_types from final_project.dwd_university_information")
    //-:将读取到的内容导出到MySQL数据库中
    df_colleges.write
      .format("jdbc")
      .option("url", "jdbc:mysql://192.168.75.104:3306/finalProject")
      .option("user", "root")
      .option("password", "123456")
      .option("dbtable", "university_information")
      .mode(SaveMode.Overwrite)
      .save()
    //-:sparkSession的停止、关闭
    sparkSession.stop()
    sparkSession.close()
  }
}
